<template>
  <div>
    <van-index-anchor index="热门城市" />
    <van-cell @click="changeIndex(item.label, item.value)" v-for="(item, index) in list" :key="index" :title="item.label" />
  </div>
</template>

<script>
import { getHotCity } from '@/api/citydata'
import { setCityToken, setCityValueToken } from '@/utils/storage'

export default {
  data () {
    return {
      list: []
    }
  },
  async created () {
    const { body } = await getHotCity()
    console.log(body)// 热门城市
    this.list = body
  },
  methods: {
    changeIndex (name, val) {
      setCityToken(name)// 将城市名存储到本地
      setCityValueToken(val)// 将城市id存储到本地
      this.$router.go(-1)
    }
  }
}
</script>

<style>

</style>
